﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public enum ControllerPadCommandState
{
    UpLeft, UpRight, DownLeft, DownRight, None
}

public class CommandPadDisplay : MonoBehaviour {
    public SteamVR_TrackedController controller;
    public ControllerPadCommandState state;
    public bool Pressed;

    public MeshRenderer ul;
    public MeshRenderer ur;
    public MeshRenderer dr;
    public MeshRenderer dl;

    public Color TouchColor;
    public Color UnTouchColor;
    public Color PressColor;

    // Update is called once per frame
    void Update () {
        ul.material.color = UnTouchColor;
        ur.material.color = UnTouchColor;
        dr.material.color = UnTouchColor;
        dl.material.color = UnTouchColor;

        
        if (controller != null && controller.padTouched)
        {
            Pressed = controller.padPressed;
            Vector2 TouchPos = new Vector2(controller.controllerState.rAxis0.x, controller.controllerState.rAxis0.y);
            Color toColor = TouchColor;
            if (Pressed) toColor = PressColor;


            if (TouchPos.y > 0)
            {
                if (TouchPos.x > 0)
                {
                    state = ControllerPadCommandState.UpRight;
                    ur.material.color = toColor;
                }
                else
                {
                    state = ControllerPadCommandState.UpLeft;
                    ul.material.color = toColor;
                }
            }
            else
            {
                if (TouchPos.x > 0)
                {
                    state = ControllerPadCommandState.DownRight;
                    dr.material.color = toColor;
                }
                else
                {
                    state = ControllerPadCommandState.DownLeft;
                    dl.material.color = toColor;
                }
            }

        }
        else
        {
            state = ControllerPadCommandState.None;
        }


    }
}
